package com.zhudeshuai.zhudemolist.util;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.NotificationCompat;

/**
 * 状态栏通知的管理类
 * <p/>
 * Created by sunxu on 16/5/12.
 */
public class NotificationManagerUtil {
    private static final int MAX = 3;
    private static int code = 0;

    /**
     * 展示状态栏
     *
     * @param context
     * @param pendingIntent
     * @param ContentText   设置上下文内容
     */
    public static void showNotification(Context context,
                                        int pendingIntentRequestCode,
                                        PendingIntent pendingIntent,
                                        int largerIcon,
                                        int smallIcon,
                                        String title,
                                        String ContentText) {

        Bitmap btm = BitmapFactory.decodeResource(context.getResources(), largerIcon);

        NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        Notification notification = new NotificationCompat.Builder(context)
                .setContentTitle(title)
                .setContentText(ContentText)
                .setTicker(ContentText)
                .setSmallIcon(smallIcon)
                .setLargeIcon(btm)
                .setPriority(Notification.PRIORITY_DEFAULT)
                .setAutoCancel(true)
                .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
                .setContentIntent(pendingIntent)
                .build();
        mNotificationManager.notify(pendingIntentRequestCode, notification); // notification
    }

    public static void showNotification(Context context,
                                        PendingIntent pendingIntent,
                                        int largerIcon,
                                        int smallIcon,
                                        String title,
                                        String ContentText) {

        showNotification(context, code++, pendingIntent, largerIcon, smallIcon, title, ContentText);
        if (code >= MAX) {
            code = 0;
        }
    }
}
